package org.x4444;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.x4444.entity.Client;
import org.x4444.entity.Order;
import org.x4444.entity.OrderDetail;
import org.x4444.entity.OrderDetail2;
import org.x4444.entity.OrderDetailPK2;
import org.x4444.entity.Product;

@Stateful
public class ProductManagerBean implements ProductManager {

	@PersistenceContext
	EntityManager em;
	
	@Override
	public Product getProduct(Integer id) {
		if (em != null && id != null) {
			Product product = em.find(Product.class, id);
			return product;
		}
		
		return null;
	}
	
	@Override
	public Client getClient(Integer id) {
		if (em != null && id != null) {
			Client client = em.find(Client.class, id);
			return client;
		}
		
		return null;
	}
	
	@Override
	public Order getOrder(Integer id) {
		if (em != null && id != null) {
			Order order = em.find(Order.class, id);
			order.getOrderDetail().size();
			//Logger.getLogger(getClass().getName()).warning("OrderDetails is null: " + (o==null));
			return order;
		}
		
		return null;
	}
	
	@Override
	public OrderDetail getOrderDetail(Integer id) {
		if (em != null && id != null) {
			OrderDetail orderDetail = em.find(OrderDetail.class, id);
			return orderDetail;
		}
		return null;
	}
	
	@Override
	public OrderDetail2 getOrderDetail2(OrderDetailPK2 id) {
		if (em != null && id != null) {
			OrderDetail2 orderDetail = em.find(OrderDetail2.class, id);
			return orderDetail;
		}
		return null;
	}
}
